import grails.converters.JSON

class ConnectionController {

     def index = { }

     def update = {
          if ( params.id != null || !params.id.trim().equals("")) {
               def document = Document.get( Long.valueOf(params.id ) )
        
               if(document != null) {
                    withFormat {
                         json { render document as JSON }
                    }
               } else {
                    def message = ['error':"Can't found Document with id ${params.id}"]
                    render message as JSON
               }
          } else {
               def message = ['error':"You must provide Document id"]
               render message as JSON
          }
          
     }
     
     def registerClient = {
          def message = ['client_id':org.apache.commons.lang.RandomStringUtils.random(10, false, true)]
          
          render message as JSON
     }
}
